package com.hfxt.controller;


import com.hfxt.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public  String login(@RequestParam(value = "username",required = false,defaultValue = "xxxx") String username,
                         @RequestParam(value = "userpwd",required = false,defaultValue = "xxxx") String userpwd){
        System.out.println("开始调用业务逻辑层");
       System.out.println("username:"+username);
        System.out.println("userpwd:"+userpwd);
        return "index";
    }

    @RequestMapping("/register")  //从controller---jsp
    public ModelAndView register(String username, String userpwd){
       // System.out.println("开始调用业务注册逻辑层");

        ModelAndView mv=new ModelAndView();
        mv.addObject("username",username);
        mv.addObject("userpwd",userpwd);
        mv.setViewName("index");
        return mv;
    }

    @RequestMapping("/register2")  //从controller---jsp
    public String register2(Map<String,Object> maps, String username, String userpwd){
        // System.out.println("开始调用业务注册逻辑层");

        maps.put("username",username);
        maps.put("userpwd",userpwd);
        return "index";
    }

    @RequestMapping("/register3")  //从controller---jsp
    public String register3(Model model, String username, String userpwd){
        // System.out.println("开始调用业务注册逻辑层");
        model.addAttribute("username",username);
        model.addAttribute("userpwd",userpwd);
        return "index";
    }

    @RequestMapping("/register4")  //从controller---jsp
    public String register4(HttpSession session, String username, String userpwd){
        // System.out.println("开始调用业务注册逻辑层");
        session.setAttribute("username",username);
        session.setAttribute("userpwd",userpwd);
        return "index";
    }

    @RequestMapping("/register5")  //从controller---jsp
    public String register5(Model model, User user){
        // System.out.println("开始调用业务注册逻辑层");
        model.addAttribute("user",user);
        return "index";
    }
}
